{#价格策略界面#}
{% extends 'laout.html' %}
{% load static %}
{% load permission %}
{% block content %}
    <div style="margin-bottom: 5px" class="clearfix">

{#        <a href="{% url 'policy_add' %}" class="btn btn-success">#}
{#            <span class="glyphicon glyphicon-plus-sign"></span>#}
{#            新建</a>#}
        {#导入simple_tag自定义模板功能 解决权限控制按钮问题  传值：request ; 按钮url的name属性  #}
        {% add_permission request 'policy_add' %}

    </div>
    <table class="table table-striped table-bordered">

    <table class="table table-bordered">
        <thead>
        <tr>
            <th>ID</th>
            <th>数量</th>
            <th>价格</th>
            {# 防止没功能时显示空白窗格          #}
            {% if request|has_permission:"policy_edit,policy_delete" %}
                <th>操作</th>
            {% endif %}
        </tr>
        </thead>
        <tbody>
        {# 切片显示前5个数据       #}
        {% for row in pager.queryset %}
{#            便于js代码定位删除#}
            <tr row-id="{{ row.id }}">
                <td>{{ row.id }}</td>
                <td>{{ row.count }}</td>
                <td>{{ row.price }}</td>
{#                <td>#}
{#                         a标签+按钮样式，实现按钮   #}
{#                        <a href="{% url 'policy_edit' pk=row.id %}" class="btn btn-primary btn-xs">编辑</a>#}
{#                        <span>|</span>#}
{#                        <a href="#" cid="{{ row.id }}" class="btn btn-danger btn-xs btn-delete" >删除</a>#}
{#                </td>#}
{#                代替以上按钮代码#}
                {% if request|has_permission:"policy_edit,policy_delete" %}
                    <td>
                        {% edit_permission request 'policy_edit' pk=row.id %}
                        {% delete_permission request 'policy_delete' pk=row.id %}
                    </td>
                {% endif %}
            </tr>
        {% endfor %}

        </tbody>
    </table>
{#    分页#}
    <ul class="pagination">
        {{ pager.html }}
    </ul>
    </table>

    {#导入 一个删除提示的模态对话框 使用警告框样式  #}
    {% include 'include/delete_modal.html' %}

{% endblock %}

{#导入js 删除模块#}
{% block js %}
    <script src="{% static 'js/delete_modal.js' %}"></script>
    <script>
        var DELETE_ID;
        {#全局变量可以在html界面单独定义#}
        var DELETE_URL = "{% url 'policy_delete' %}";
    </script>

{% endblock %}